package cn.edu.fzu.homemaking.io;

import java.util.List;

import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.ArrayUtils;
import org.joda.time.DateTime;

import lombok.Data;

/**
 * markdown 格式消息
 * 
 * @author fangxin
 * @date 2022年11月10日
 */
@Data
public class MarkdownMessage {

    private static final String   TIME_FORMAT   = "yyyy-MM-dd HH:mm:ss";

    private String                title;
    private String                text;

    private static final String[] EMPTY_STRINGS = new String[0];

    public MarkdownMessage(String title, String content) {
        this(null, title, content, EMPTY_STRINGS);
    }


    public MarkdownMessage(List<String> mobiles, String title, String content, String... items) {

        StringBuilder sb = new StringBuilder(128);
        sb.append("## ").append(title).append('\n');
        sb.append("### ").append(content).append('\n');
        sb.append("- Time: ").append(DateTime.now().toString(TIME_FORMAT));

        if (ArrayUtils.isNotEmpty(items)) {
            for (String i : items) {
                sb.append("\n- ").append(i);
            }
        }
        if (CollectionUtils.isNotEmpty(mobiles)) {
            for (String mobile : mobiles) {
                sb.append("\n### ").append("@").append(mobile).append("\n");
            }
        }

        this.title = title;
        this.text = sb.toString();

    }

}
